package demo15

// 备忘录设计模式
import "fmt"

// memento

type Memento interface{}
type Game struct{
	hp,mp int
}

type gameMemento struct{
	hp,mp int
}

func NewGame(hp,mp int) *Game{
	return &Game{
		hp:hp,
		mp:mp,
	}
}

func (g *Game)Save() *gameMemento{
	return &gameMemento{
		hp:g.hp,
		mp:g.mp,
	}
}

func (g *Game)Play(hp,mp int){
	g.hp+=hp
	g.mp+=mp
}

func (g *Game)Status(){
	fmt.Println(g.hp,g.mp)
}

func (g *Game) Load(m Memento){
	memento := m.(*gameMemento)
	g.hp = memento.hp
	g.mp = memento.mp
}